module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	var Test = /*@__PURE__*/ (function(Component) {
		function Test(props) {
			Component.call(this, props);
			this.data = {
				devicePosition: "back",
				previewUrl: "",
				videoThumbPath: "",
				videoPath: "",
				scanCodeMode: false
			};
		}

		if (Component) Test.__proto__ = Component;
		Test.prototype = Object.create(Component && Component.prototype);
		Test.prototype.constructor = Test;
		Test.prototype.onstop = function(e) {
			console.log("onstop");
		};
		Test.prototype.onerror = function(e) {
			console.log("onerror");
		};
		Test.prototype.oninitdone = function(e) {
			console.log("oninitdone");
		};
		Test.prototype.onscancode = function(e) {
			var text = e.detail.text;
			api.alert({
				msg: text
			});
		};
		Test.prototype.switchMode = function(e) {
			this.data.scanCodeMode = !this.data.scanCodeMode;
		};
		Test.prototype.takePhoto = function(e) {
			var this$1 = this;

			var obj = document.getElementById("camera");
			if (obj.takePhoto) {
				var that = this;

				obj.takePhoto(
					{
						quality: "high"
					},
					function(ret, err) {
						that.data.previewUrl = ret.tempImagePath;
					}
				);
			} else {
				var ctx = wx.createCameraContext();
				ctx.takePhoto({
					quality: "high",
					success: function(res) {
						this$1.data.previewUrl = res.tempImagePath;
						console.log(res.tempImagePath);
						api.ajax(
							{
								url:
									"https://a6196736472444-dev.apicloud-saas.com/api/employees/upload",
								method: "post",
								data: {
									values: {
										filename: "icon.jpg"
									},

									files: {
										file: res.tempImagePath
									}
								}
							},

							function(ret, err) {
								console.log(ret);
							}
						);
					}
				});
			}
		};
		Test.prototype.startRecord = function(e) {
			var obj = document.getElementById("camera");
			obj.startRecord({
				quality: "high"
			});
		};
		Test.prototype.stopRecord = function(e) {
			var that = this;
			var obj = document.getElementById("camera");
			obj.stopRecord(
				{
					quality: "high"
				},
				function(ret, err) {
					that.data.videoThumbPath = ret.tempThumbPath;
					that.data.videoPath = ret.tempVideoPath;
				}
			);
		};
		Test.prototype.switchDevicePosition = function() {
			this.data.devicePosition =
				this.data.devicePosition == "back" ? "front" : "back";
		};
		Test.prototype.render = function() {
			return apivm.h(
				"scroll-view",
				{class: "main", "scroll-y": true},
				apivm.h(
					"button",
					{onclick: this.switchMode},
					this.data.scanCodeMode ? "切换为拍照" : "切换为扫码"
				),
				this.data.scanCodeMode
					? apivm.h("camera", {
							id: "camera",
							mode: "scanCode",
							onstop: this.onstop,
							onerror: this.onerror,
							oninitdone: this.oninitdone,
							onscancode: this.onscancode
					  })
					: apivm.h(
							"view",
							null,
							apivm.h("camera", {
								id: "camera",
								"device-position": this.data.devicePosition,
								onstop: this.onstop,
								onerror: this.onerror,
								oninitdone: this.oninitdone
							}),

							apivm.h("button", {onclick: this.takePhoto}, "拍照"),
							apivm.h("button", {onclick: this.startRecord}, "开始录制"),
							apivm.h("button", {onclick: this.stopRecord}, "停止录制"),
							apivm.h("button", {onclick: this.switchDevicePosition}, "切换摄像头"),

							apivm.h("text", null, "图片预览："),
							apivm.h("image", {
								id: "image",
								src: this.data.previewUrl,
								mode: "widthFix"
							}),
							apivm.h("text", null, "视频预览："),
							apivm.h("video", {
								id: "video",
								src: this.data.videoPath,
								poster: this.data.videoThumbPath
							})
					  )
			);
		};

		return Test;
	})(Component);
	apivm.define("test", Test);
	apivm.render(apivm.h("test", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}